import datetime
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

# Create your models here.
class UserProfile(models.Model):
    MEMBER_CHOICES = (
        ('G', 'General'),
        ('S', 'Student'),
        ('O', 'Other'),
        ('E', 'Exec'),
    )
    JERICHO_CHOICES = (
        ('C', 'Current'),
        ('S', 'Single'),
        ('F', 'Family'),
    )
    # This field is required.
    user = models.OneToOneField(User)
    #profile
    student_number = models.CharField(max_length=60)
    phone_mobile = models.CharField(max_length=12)
    phone_home = models.CharField(max_length=12)
    address = models.CharField(max_length=200)
    city = models.CharField(max_length=200)
    postal_code = models.CharField(max_length=7)
    #membership
    jericho_member_type = models.CharField('Jericho Membership Type', max_length=1,choices=JERICHO_CHOICES)
    join_date = models.DateField('Joined Date', default = datetime.date.today())
    expiry_date = models.DateField('Expiry Date', default = datetime.date.today())
    member_type = models.CharField('Member Type', max_length=1,choices=MEMBER_CHOICES)
    suspended = models.BooleanField('Is Suspended?')
    active = models.BooleanField('Is Active?')
    #access
    hid_number = models.CharField('HID Number', max_length=60)
    access_clubroom = models.BooleanField("Clubroom access")
    access_fixit = models.BooleanField("FixIt access")
    access_multiskiff = models.BooleanField("Multihull/Skiff access")
    access_windsurfl1 = models.BooleanField("Windsurf L1 access")
    access_windsurfl2 = models.BooleanField("Windsurf L2 access")
    access_kayak = models.BooleanField("Kayak access")

class UserQualification(models.Model):
    QUALIFICATIONS_CHOICES = (
        ('Monohull',(
         ('MN', 'Not Qualified'),
         ('MB', 'Beginner'),
         ('MI', 'Intermediate'),
         ('M1', 'Advance I'),
         ('M2', 'Advance II'),
         ('M3', 'Advance III')
            )),
        ('Multihull',(
         ('HN', 'Not Qualified'),
         ('H0', 'L0'),
         ('H1', 'L1'),
         ('H2', 'L2'),
            )),
        ('Windsurf',(
         ('WN', 'Not Qualified'),
         ('W1', 'L1'),
         ('W2', 'L2'),
         ('WH', 'High Wind'),
            )),
        ('Kayak',(
         ('KN', 'Not Qualified'),
         ('K1', 'L1'),
            ))
        )
    user = models.ForeignKey(User)
    qualification = models.CharField('Qualification', max_length=2,choices=QUALIFICATIONS_CHOICES)
    issued = models.DateField(default = datetime.date.today())

class UserMemo(models.Model):
    user = models.ForeignKey(User)
    memo = models.TextField()
    issued = models.DateField(default = datetime.date.today())

class UserCreditMemo(models.Model):
    user = models.ForeignKey(User)
    memo = models.TextField()
    amount = models.CommaSeparatedIntegerField(max_length=12)
    payed = models.BooleanField()
    issued = models.DateField(default = datetime.date.today())

class InventoryItem(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField()
    on_hand = models.IntegerField()

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)





